@extends('layouts.app')
@section('content')
    <form method="POST"  name="formInfo" id="formInfo">
    <div class="weui-tab">
        <input type="hidden" name="_token" id="_token" value="{{csrf_token()}}">
        <div class="weui-cells weui-cells_form no-border">
            <div class="weui-cells no-border">
                <div class="weui-cell">
                    <div class="weui-cell__hd mr-10">
                        <svg class="icon f28" aria-hidden="true">
                            <use xlink:href="#icon--17"></use>
                        </svg>
                        手机号：
                    </div>
                    <div class="weui-cell__bd">
                        <input class="weui-input" name="mobile" type="text" placeholder="请输入用手机号">
                    </div>
                </div>
                <div class="weui-cell">
                    <div class="weui-cell__hd mr-10">
                        <svg class="icon f28 white" aria-hidden="true"></svg>
                    </div>
                    <div class="weui-cell__bd">

                        <input class="weui-input-border" name="validateCode" type="text" placeholder="请输入验证码">
                    </div>
                    <div class="weui-cell__ft">
                        <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_blue get-code">获取验证码</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="demos-content-padded">
        <a href="javascript:;" class="weui-btn weui-btn_primary_a next" data-target="#full">下一步</a>
    </div>
{{--找回密码--}}
    <div id="full" class="weui-popup__container">
        <div class="weui-popup__overlay"></div>
        <div class="weui-popup__modal">
            <article class="weui-article">
                <div class="weui-cells no-border">
                    <div class="weui-cell">
                        <div class="weui-cell__hd mr-10">
                            输入新密码：
                        </div>
                        <div class="weui-cell__bd">
                            <input class="weui-input " name="password" placeholder="请输入新密码">
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd mr-10">
                            确认新密码：
                        </div>
                        <div class="weui-cell__bd">
                            <input class="weui-input " name="cpassword" placeholder="请确认密码">
                        </div>
                    </div>

                </div>

            </article>
            <div class="demos-content-padded_MS">
                <a href="javascript:;" class="weui-btn weui-btn_primary_a btn-confirm">确认</a>
            </div>
        </div>
    </div>
</form>
<script>
        var timer;
        // 点击获取验证码
        $(".get-code").click(function () {
            console.log("timer", timer);
            var mobile = $("input[name='mobile']").val();
            var _token = $("input[name='_token']").val();
            if (mobile) {
                $.post("/sendCode2", {
                    _token: _token,
                    mobile: mobile
                }, function (res) {
                    console.log("res", res);
                    $.toast(res.info, 'text');
                    if (res.code == 10000) {
                        if (!timer) {
                            countdown(60);
                        }
                    }
                });
            } else {
                $.toast("手机号不能为空！", 'text');
            }

        });

        // 倒计时
        function countdown(num) {
            if (num > 0) {
                num--;
                $(".get-code").text("重新发送(" + num + ")").addClass("weui-btn_gray");
            } else {
                clearTimeout(timer);
                timer = 0;
                $(".get-code").text("发送验证码").addClass("weui-btn_blue");
                return;
            }
            console.log("num", num);
            timer = setTimeout(function () {
                countdown(num);
            }, 1000);
        }
        //下一步
        $(".next").click(function () {
            var mobile = $("input[name='mobile']").val();
            var info = InputStrategy.check("isMobile",mobile);
            if (info) {
                return $.toast(info, "text");
            }
            $("#full").popup();
        });
     // 确认 提交表单
        $(".btn-confirm").click(function () {
            console.log("66");
            var password = $("input[name='password']").val();
            var cpassword = $("input[name='cpassword']").val();
            if (!password || !cpassword) {
                return $.toast("请输入密码", 'text')
            }
            if (password !== cpassword) {
                 return $.toast("密码不一致", 'text')
            }

            save("/mobile/forgot", "#formInfo", '/mobile/login', function (res) {
                console.log("rr", res);
                if (res.code == 10000) {
                    $.closePopup();
                }
            });
        });
</script>
@endsection
